from pathlib import Path
import csv
from datetime import datetime
import matplotlib.pyplot as plt

path = Path('sitka_weather_2021_simple.csv')
lines = path.read_text().splitlines()

reader = csv.reader(lines)
header_row = next(reader)

# 提取最高温度
dates,highs,lows = [],[],[]
for row in reader:
    current_date = datetime.strptime(row[2],'%Y-%m-%d')
    dates.append(current_date)
    high = int(row[4])
    highs.append(high)
    low = int(row[5])
    lows.append(low)

# 根据最高温度绘图
plt.style.use('seaborn-v0_8')
fig,ax = plt.subplots()
ax.plot(dates,highs,color = 'red',alpha=0.5)
ax.plot(dates,lows,color = 'blue',alpha=0.5)
ax.fill_between(dates,highs,lows,facecolor = 'blue',alpha=0.1)

# 设置绘图的格式
ax.set_title('Daily High and Low Temperatures ,2021',fontsize=24)
ax.set_xlabel('',fontsize = 16)
fig.autofmt_xdate()
ax.set_ylabel('Temperature(F)',fontsize=16)
ax.tick_params(labelsize=16)

# 绘图
plt.show()